//
//  StepCountViewController.m
//  EasyChat
//
//  Created by romana on 16/6/14.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "StepCountViewController.h"
#import "QYPedometerManager.h"


@interface StepCountViewController ()

@property(nonatomic, retain) UILabel *stepsLabel;


@end

@implementation StepCountViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.stepsLabel = [[UILabel alloc]
                       initWithFrame:CGRectMake(20, 150,
                                                [UIScreen mainScreen].bounds.size.width - 40,
                                                200)];
    _stepsLabel.numberOfLines = 6;
    _stepsLabel.backgroundColor = [UIColor redColor];
    _stepsLabel.textColor = [UIColor whiteColor];
    [self.view addSubview:_stepsLabel];
    __block StepCountViewController *weakSelf = self;
    
    if ([QYPedometerManager isStepCountingAvailable]) {
        [[QYPedometerManager shared] startPedometerUpdatesTodayWithHandler:^(QYPedometerData *pedometerData, NSError *error) {
            
            if (!error) {
                weakSelf.stepsLabel.text = [NSString
                                            stringWithFormat:@" 步数:%@\n 距离:%@\n 爬楼:%@\n 下楼:%@\n 活动时间:%@",
                                            pedometerData.numberOfSteps,
                                            pedometerData.distance,
                                            pedometerData.floorsAscended,
                                            pedometerData.floorsDescended,
                                            pedometerData.currentCadence];
            }
            
            
        }];
    }else{
    
        UIAlertView *alertView = [[UIAlertView alloc]
                                  initWithTitle:@"此设备不支持记步功能"
                                  message:@"仅支持iPhone5s及其以上设备"
                                  delegate:self
                                  cancelButtonTitle:nil
                                  otherButtonTitles:@"OK", nil];
        [alertView show];
    
    
    
    }
    
    
    // Do any additional setup after loading the view.
}


@end
